#include "sparkfunLCD.h"

void SFLCDinit(void)
{
	// From HD44780 datasheet
	LCDwrite4bits(0x03);
	delayms(10);
	LCDwrite4bits(0x03);
	delayms(1);
	LCDwrite4bits(0x03);
	delayms(1);
	LCDwrite4bits(0x02);
	delayms(1);
	
	LCDwriteCommand(0x28, RS_LOW);		// 2 lines
	LCDwriteCommand(0x0C, RS_LOW);		// display on
	LCDwriteCommand(0x01, RS_LOW);		// clear display
	LCDwriteCommand(0x06, RS_LOW);		// increment (entry mode)	
}

void SFLCDmoveCursor(char row, char col)
{
	switch(row)
	{
		case 0:
			LCDsetDDaddr(col);
			break;
		case 1:
			LCDsetDDaddr(col + 0x40);
			break;
		case 2:
			LCDsetDDaddr(col + 0x14);
			break;
		case 3:
			LCDsetDDaddr(col + 0x54);
			break;
		default:
			LCDsetDDaddr(0x00);
	}
}

char SFLCDprint(char* string)
{
	int i = 0;
	while(string[i] != 0)
	{
		LCDwrite(string[i++]);
	}
	return i;
}
